package com.edu.controller;

import com.edu.bean.Book;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class BookController {

    //路径级别的参数，用简单类型来接受，那么必须使用 @PathVariable
//    @RequestMapping("/book/{id}")
//    public String showBook(@PathVariable("id") int bookId) {
//        System.out.println("查询了id为:"+bookId+"的书的信息");
//        //把查询到的书的信息 返回给客户端 m
//        return "/book.jsp";
//    }

    //  路径级别的参数，使用对象进行接受，占位符的名字 必须和对象的属性名一致
    @RequestMapping("/book/{bookId}")
    public String showBook(Book book) {
        System.out.println("查询了id为:"+book.getBookId()+"的书的信息");
        //把查询到的书的信息 返回给客户端 m
        return "/book.jsp";
    }


    @RequestMapping("/{wid}/book/{bid}")
    public String showBook(@PathVariable("wid") int writerId,@PathVariable("bid") int bookId) {
        System.out.println("作者id为:"+writerId);
        System.out.println("书id为:"+bookId);
        return "/book.jsp";
    }

    @RequestMapping("/books/{bookName}/{bookId}")
    public String showBook2(Book book) {
        System.out.println(book);
        return "/book.jsp";
    }
}
